///*
// * Copyright (c) 2020 hebeiyiliuba.com
// * All rights reserved.
// *
// */
//
//package org.jeecg.modules.middleware.quartz.job.jgupload;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import org.apache.commons.collections4.CollectionUtils;
//import org.jeecg.common.constant.enums.ReportPlatformEnum;
//import org.jeecg.common.util.DateUtils;
//import org.jeecg.modules.wlhy.company.entity.HyCompanyConfig;
//import org.jeecg.modules.wlhy.company.service.IHyCompanyConfigService;
//import org.jeecg.modules.wlhy.report.impl.HubeiReportService;
//import org.jeecg.modules.wlhy.shipping.entity.HyShippingNote;
//import org.jeecg.modules.wlhy.shipping.service.IHyShippingNoteService;
//import org.jeecg.modules.wlhy.utils.HyCfgUtil;
//import org.quartz.*;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import java.text.SimpleDateFormat;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.GregorianCalendar;
//import java.util.List;
//
///**
// * @Description: 湖北上报脚本
// * @author: duanlikao
// * @date: 2022年10月09日 11:31
// */
//
//@PersistJobDataAfterExecution
//@DisallowConcurrentExecution
//public class HubeiUploadJobService  implements Job {
//
//    private static final Logger LOGGER = LoggerFactory.getLogger(HubeiUploadJobService.class);
//
//    public SimpleDateFormat now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//    @Autowired
//    private IHyShippingNoteService shippingNoteService;
//
//    @Autowired
//    private IHyCompanyConfigService companyConfigService;
//
//    @Autowired
//    private HubeiReportService hubeiReportService;
//
//    //@Scheduled(cron = "0 30 2 * * ?")//每天的4:30:00执行
//    @Override
//    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
//        if(!HyCfgUtil.isUsed("hubei_report")){
//            LOGGER.info("湖北上报服务暂未开启,请联系管理。");
//            return;
//        }
//
//        List<HyCompanyConfig> companyConfigs = companyConfigService.list(new QueryWrapper<HyCompanyConfig>()
//                .eq("report_platform_type", ReportPlatformEnum.REPORT_PLATFORM_HUBEI.getCode())
//                .eq("auto_report",1)
//        );
//        if(CollectionUtils.isEmpty(companyConfigs)) {
//            LOGGER.info("HubeiUploadJobService autoUploadHubeiShippingNot: 没有分公司配置自动上报 !" );
//            return;
//        }
//        Long start = System.currentTimeMillis();
//        LOGGER.info("HubeiUploadJobService autoUploadHubeiShippingNot:执行运单上报数据开始" + now.format(new Date()));
//
//        Calendar calendar = new GregorianCalendar();
//        calendar.setTime(new Date());
//        calendar.add(Calendar.DATE, -60);// 把日期往后增加一天.整数往后推,负数往前移动
//        Date lasDate = calendar.getTime(); // 这个时间就是日期往后推一天的结果
//        String startDateString =  DateUtils.date2Str(lasDate, DateUtils.date_sdf.get());
//        String endDateString =  DateUtils.dateTimeToString(new Date());
//
//        for (HyCompanyConfig companyConfig : companyConfigs) {
//
//            QueryWrapper<HyShippingNote> queryWrapper = new QueryWrapper();
//            queryWrapper.eq("shipping_pay_status","6");
//            queryWrapper.eq("company_id",companyConfig.getCompanyId());
//            queryWrapper.ne("upload_status","1");
//            queryWrapper.between("pay_dt",startDateString+" 00:00:00", endDateString );
//            queryWrapper.orderByAsc("pay_dt");
//
//            List<HyShippingNote> shippingNotes = shippingNoteService.list(queryWrapper);
//            if(CollectionUtils.isEmpty(shippingNotes)) {
//                LOGGER.info("HubeiUploadJobService autoUploadHubeiShippingNot: no data handling !" );
//                continue;
//            }
//
//            for(HyShippingNote hyShippingNote:shippingNotes){
//                try {
//                     hubeiReportService.report(hyShippingNote);
//                }catch (Exception e){
//                    LOGGER.info("HubeiUploadJobService autoUploadHubeiShippingNot:Exception : {}" ,e.getMessage());
//                    continue;
//                }
//            }
//        }
//
//        LOGGER.info("HubeiUploadJobService autoUploadHubeiShippingNot:执行运单上报数据结束,耗时:"+(System.currentTimeMillis()-start)+"毫秒----");
//
//    }
//
//}
